<script setup>
import { ref, onMounted } from 'vue'

import { useHeroStore } from '@/stores/hero'
import { useDialogStore } from '@/stores/dialog'
import EquipmentItem from '@/components/equipment-item.vue';

const heroStore = useHeroStore();
const dialogStore = useDialogStore();

onMounted(() => {
    heroStore.getHeroPage();
})

const currentChange = () => {
    heroStore.pageDTO.pageNum = heroStore.heroPage.pageNum;
    heroStore.getHeroPage();
}


const heroImgClick = (heroId) => {
    dialogStore.open(heroId);
}


</script>
<template>
    <div class="hero-view">
        <el-row class="hero-search">
            <el-col :span="24">
                <el-input v-model="heroStore.pageDTO.name" style="width: 240px" size="large" placeholder="请输入英雄名称"
                    :suffix-icon="Search" />
                <el-button type="primary" style="margin-left: 10px;" @click="heroStore.getHeroPage()"
                    round>搜索</el-button>

            </el-col>
        </el-row>
        <el-row class="hero-list">
            <template v-for="item in heroStore.heroPage.datas">
                <hero-item :heroId="item.id" :heroName="item.name" :imgUrl="'/api/file/download/' + item.imgFileId"
                    @imgClick="heroImgClick"></hero-item>
            </template>
            <el-dialog v-model="dialogStore.dialogVisible" title="新增推荐出装" width="1100" :before-close="dialogStore.close">
                <div>
                    <el-row>
                        <el-col :span="8">
                            <hero-item :heroId="dialogStore.heroData.id" :heroName="dialogStore.heroData.name" :imgUrl="'/api/file/download/' + dialogStore.heroData.imgFileId" />
                        </el-col>
                        <el-col :span="16">
                            <div class="equipments">
                                <template v-for="item in dialogStore.equipmentData">
                                    <EquipmentItem :equipmentName="item.name" :imgUrl="'/api/file/download/'+item.imgFileId" />
                                </template>
                            </div>
                        </el-col>
                    </el-row>
                    <div class="equipment-type">
                        <div class="equipment-type-items">
                            <span class="title">出门装</span>
                            <span class="select-items">
                                <equipment-select-item :id="1" imgUrl="/api/file/download/1817179575889694722"></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                            </span>
                        </div>
                        <div class="equipment-type-items">
                            <span class="title">出门装</span>
                            <span class="select-items">
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                            </span>
                        </div>
                        <div class="equipment-type-items">
                            <span class="title">出门装</span>
                            <span class="select-items">
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                                <equipment-select-item></equipment-select-item>
                            </span>
                        </div>
                    </div>
                </div>
                <template #footer>
                    <div class="dialog-footer">
                        <el-button @click="dialogVisible = false">点我</el-button>
                    </div>
                </template>
            </el-dialog>

        </el-row>
        <el-row class="hero-page">
            <el-col :span="12">

            </el-col>
            <el-col :span="12">
                <el-pagination layout="prev, pager, next" :page-size="heroStore.heroPage.pageSize"
                    v-model:current-page="heroStore.heroPage.pageNum" :total="heroStore.heroPage.total"
                    @current-change="currentChange()" />
            </el-col>
        </el-row>
    </div>
</template>
<style lang="less" scoped>
.hero-view {
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;

    .hero-search {
        height: 50px;
    }

    .hero-list {
        min-height: 500px;
        flex: 1;
    }

    .hero-page {
        height: 50px;
    }
}

.equipments{
    border: 1px solid red;
    height: 300px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    overflow: hidden;
    overflow-y: auto;
}

.equipment-type{
    margin-top: 20px;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    .equipment-type-items{
        padding: 5px;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;

        .title{
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .select-items{
            display: flex;
            flex-direction: row;
        
        }
    }
}
</style>